package com.miyu.video.service.impl;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import com.miyu.common.pojo.PageServe;
import com.miyu.common.pojo.system.SysRule;
import com.miyu.video.dao.VideoDao;
import com.miyu.video.service.VideoService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 视频服务impl
 * @author MIYU
 */
@Service
public class VideoServiceImpl implements VideoService {

    @Resource
    private VideoDao videoDao;
    @Resource
    private VideoService videoService;
    @Override
    @Cacheable(cacheNames  = "system:sysRule" ,key = "#ruleId")
    public SysRule getSysRuleById(String ruleId) {
        SysRule SysRule = videoDao.findByRuleId(ruleId);
        return SysRule;
    }

    /**
     * 视频首页导航菜单
     * @param param 参数
     * @return {@link JSONArray}
     */
    @Override
    public JSONArray queryVideoNav(JSONObject param) {
        String ruleId = param.getString("ruleId");

        SysRule sysRule = videoService.getSysRuleById(ruleId);
        System.out.println(sysRule);
        JSONArray exploreUrl = JSONArray.parseArray(JSONObject.parse(sysRule.getRuleSet()).getString("exploreUrl"), JSONReader.Feature.IgnoreSetNullValue);


        //爬虫执行
        PageServe pageServe = new PageServe();
        pageServe.setUrl("https://dianyi.ng/v/dongman.html");

        return exploreUrl;
    }
}
